import Flutter
import UIKit
import AlibabaCloudRUM

@main
@objc class AppDelegate: FlutterAppDelegate {
   
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    AlibabaCloudRUM.setConfigAddress("https://gt4la9x12a-default-cn.rum.aliyuncs.com/RUM/config")
    AlibabaCloudRUM.start("gt4la9x12a@1464cc9829ffb3d")// AppID，步骤一创建RUM应用时获取。
    print("创建")

    let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
      let myChannel = FlutterMethodChannel(name:"com.test.sentry",binaryMessenger:controller.binaryMessenger)
      myChannel.setMethodCallHandler{(call, result) in
          if call.method == "testThrow"{
              self.testError()
              result("error")
          }else{
              result(FlutterMethodNotImplemented)
          }
          
      }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

  func testError() -> Void {
    // 强制崩溃
    let array = [1, 2, 3]
    print(array[5])  // 越界访问，模拟崩溃
  }
}
